import Vue from 'vue'
import Vuex from 'vuex'
import axios from 'axios'

Vue.use(Vuex);

export default new Vuex.Store({
    state: {
        auth: false,
        userDetail: {
            username: 'zhangsan001',
            userId: '99',
            nickname: 'Jam',
            lastLoginTime: null,
        },
        //枚举三属性index name text
        leaveTypes:[],
        applyStates:[],
        auditStates:[],



    },
    mutations: {
        setUserDetail: function (state, userDetail) {
            //  state.user.userCode = userCode;
            state.userDetail = userDetail;
        },
        setAuth: function (state, auth) {
            state.auth = auth
        }
    },
    actions: {
        initLeaveTypes: function (context) {
            axios({
                method: 'get',
                url: '/basic/LeaveTypes',
            }).then(res => {
                console.log(JSON.stringify(res.data));
                context.state.leaveTypes=res.data
            });
        },
        initApplyStates:function (context) {
            axios({
                method: 'get',
                url: '/basic/ApplyStates',
            }).then(res => {
                console.log(JSON.stringify(res.data));
                context.state.applyStates=res.data
            });
        },
        initAuditStates:function (context) {
            axios({
                method: 'get',
                url: '/basic/AuditStates',
            }).then(res => {
                console.log(JSON.stringify(res.data));
                context.state.auditStates=res.data
            });
        },

    }
})
